﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class WorkerDAO : BaseService
    {
       
        public IList<Worker> GetItemList()
        {
           return  this.GetItemList<Worker>("from Worker");
        }
        public Com.CMS263.PO.Worker Login(string userName, string password)
        {
            IList<Worker> list = DBHelper.ExecuteHQL("from Worker where UserName='" + userName + "' and UserPass='" + password + "'").List<Worker>();
            if (list.Count > 0)
            {
                return list.First();
            }
            else
            {
                return null;
            }
        }
        public bool isExist(string userName)
        {
            return DBHelper.ExecuteHQL("from Worker where UserName='" + userName + "'").List().Count > 0;
        }
        /// <summary>
        /// 根据角色查询用户信息
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public IList<Worker> GetItemListByRole(string roleID)
        {
            string hql = "from Worker where 1=1";
            if (roleID=="0")
            {
                
            }
            else
            {
                hql += " and Role in("+roleID+")" ;
            }
            return this.GetItemList<Worker>(hql);
        }
        public IList<Worker> GetWorkerByPaging(int page, int pagesize)
        {
            string hql = " from Worker where 1=1";
            return FindList<Worker>(hql, null, ((page - 1) * pagesize), pagesize);
        }
        public int GetWorkerByPaging()
        {
            string hql = " select count(*) from Worker where 1=1";
            return Convert.ToInt32(GetValue(hql));
        }
        /// <summary>
        /// 查询全部用户信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<Worker> GetAllWorker(int page, int pagesize)
        {
            string hql = "from Worker where 1=1";
            return FindList<Worker>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 查询全部用户数量
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public int GetAllWorkerCount()
        {
            string hql = "select count(*) from Worker where 1=1";
            return Convert.ToInt32(GetValue(hql));
        }
        
    }
}
